package com.grm.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.grm.common.enums.ErrorEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result {
    public static final int SUCCESS_CODE = 200;
    public static final String DEFAULT_SUCCESS_MESSAGE = "成功！";
    public static final int DEFAULT_FAILED_CODE = 500;

    private int code;
    private String message;
    private Object data;
    private Long total;

    public static Result success() {
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,null,null);
    }

    public static Result success(Object data) {
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,data,null);
    }

    public static Result success(Object data,Long total) {
        return new Result(SUCCESS_CODE,DEFAULT_SUCCESS_MESSAGE,data,total);
    }
    public static Result success(Object data,String message) {
        return new Result(SUCCESS_CODE,message,data,null);
    }

    public static Result failed(String message){
        return new Result(DEFAULT_FAILED_CODE,message,null,null);
    }
    public static Result failed(int code,String message){
        return new Result(code,message,null,null);
    }
    public static Result failed(ErrorEnum errorEnum){
        return new Result(errorEnum.getCode(),errorEnum.getMessage(),null,null);
    }
}
